#pragma once

#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/spi/spidev.h>
#include <cstring>

class Mjbot_SPI_Interface
{
public:
    Mjbot_SPI_Interface(const char* h_spi, int freq, int delay, int bits_per_word, int mode);
    int send(uint8_t dev, uint16_t id, uint8_t *pdata, uint8_t length);
    int receive(uint8_t dev, uint16_t *id, uint8_t* pdata, uint8_t *length);
    int mjbots_control(uint8_t dev, uint16_t id, float pos, float vel, float torque, float kp, float kd);
    int mjbots_feedback(uint8_t dev, uint16_t *id, float *pos, float *vel, float *torque);
private:
    const char* h_spi;
    uint32_t spi_freq;
    uint16_t delay;
    uint8_t bits_per_word;
    uint8_t mode;
    int spi_fd;
};
